home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-finimp.adb < prev    next >
Text File  |  1996-01-30  |  4KB  |  111 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --    S Y S T E M . F I N A L I Z A T I O N _ I M P L E M E N T A T I O N   --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.14 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with Ada.Finalization; use Ada.Finalization;
  27.  
  28. package body System.Finalization_Implementation is
  29.  
  30.    --------------------------
  31.    -- Attach_To_Final_List --
  32.    --------------------------
  33.  
  34.    procedure Attach_To_Final_List (
  35.      L   : in out Finalizable_Ptr;
  36.      Obj : in out Finalizable) is
  37.  
  38.    begin
  39.       if L /= null then
  40.          Obj.Next := L;
  41.          Finalizable (L.all).Prev := Obj'Access;
  42.       else
  43.          Obj.Next := null;
  44.       end if;
  45.  
  46.       Obj.Prev := null;
  47.       L := Obj'Access;
  48.    end Attach_To_Final_List;
  49.  
  50.    -------------------
  51.    -- Finalize_List --
  52.    -------------------
  53.  
  54.    procedure Finalize_List (L : Finalizable_Ptr) is
  55.       P     : Finalizable_Ptr := L;
  56.       Q     : Finalizable_Ptr;
  57.       Error : Boolean := False;
  58.  
  59.    begin
  60.       --  ??? pragma Abort_Defer;
  61.       while P /= null loop
  62.          Q := Finalizable (P.all).Next;
  63.          begin
  64.             Finalize (Root'Class (P.all));
  65.          exception
  66.             when others => Error := True;
  67.          end;
  68.          P := Q;
  69.       end loop;
  70.  
  71.       if Error then
  72.          raise Program_Error;
  73.       end if;
  74.    end Finalize_List;
  75.  
  76.    procedure Finalize_Global_List is
  77.    begin
  78.       Finalize_List (Global_Final_List);
  79.    end Finalize_Global_List;
  80.  
  81.    ------------------
  82.    -- Finalize_One --
  83.    ------------------
  84.  
  85.    procedure Finalize_One (
  86.      From   : in out Finalizable_Ptr;
  87.      Obj    : in out  Finalizable) is
  88.  
  89.    begin
  90.       --  ??? pragma Abort_Defer;
  91.       if Obj.Prev = null then
  92.  
  93.          --  It must be the first of the list
  94.          From := Obj.Next;
  95.       else
  96.  
  97.          Finalizable (Obj.Prev.all).Next := Obj.Next;
  98.       end if;
  99.  
  100.       if Obj.Next /= null then
  101.          Finalizable (Obj.Next.all).Prev := Obj.Prev;
  102.       end if;
  103.  
  104.       Finalize (Root'Class (Obj));
  105.  
  106.    exception
  107.       when others => raise Program_Error;
  108.    end Finalize_One;
  109.  
  110. end System.Finalization_Implementation;
  111.